package cn.springmvc.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.springmvc.model.Prices1;
import cn.springmvc.model.Prices2;
import cn.springmvc.model.Prices3;
import cn.springmvc.model.Prices4;
import cn.springmvc.model.Prices5;
import cn.springmvc.model.Prices6;
import cn.springmvc.model.Prices7;
import cn.springmvc.model.Prices8;
import cn.springmvc.service.Price1Service;
import cn.springmvc.service.Price2Service;
import cn.springmvc.service.Price3Service;
import cn.springmvc.service.Price4Service;
import cn.springmvc.service.Price5Service;
import cn.springmvc.service.Price6Service;
import cn.springmvc.service.Price7Service;
import cn.springmvc.service.Price8Service;

@Controller
public class PriceController {
@Autowired
 private Price1Service price1Service;
@Autowired
private Price2Service price2Service;
@Autowired
private Price3Service price3Service;
@Autowired
private Price4Service price4Service;
@Autowired
private Price5Service price5Service;
@Autowired
private Price6Service price6Service;
@Autowired
private Price7Service price7Service;
@Autowired
private Price8Service price8Service;

@RequestMapping(value="/insertps1",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs1(@RequestBody Prices1 ps1){
	Map<String, Object> ret=new HashMap<>();
	int year=ps1.getNianfen();
	List<Prices1> st1=price1Service.getPrices1ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price1Service.insert(ps1);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps2",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs2(@RequestBody Prices2 ps2){
	Map<String, Object> ret=new HashMap<>();
	int year=ps2.getNianfen();
	List<Prices2> st1=price2Service.getPrices2ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price2Service.insert(ps2);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps3",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs3(@RequestBody Prices3 ps3){
	Map<String, Object> ret=new HashMap<>();
	int year=ps3.getNianfen();
	List<Prices3> st1=price3Service.getPrices3ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price3Service.insert(ps3);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps4",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs4(@RequestBody Prices4 ps4){
	Map<String, Object> ret=new HashMap<>();
	int year=ps4.getNianfen();
	List<Prices4> st1=price4Service.getPrices4ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price4Service.insert(ps4);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps5",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs5(@RequestBody Prices5 ps5){
	Map<String, Object> ret=new HashMap<>();
	int year=ps5.getNianfen();
	List<Prices5> st5=price5Service.getPrices5ByNianfen(year);
	if (!st5.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price5Service.insert(ps5);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps6",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs6(@RequestBody Prices6 ps6){
	Map<String, Object> ret=new HashMap<>();
	int year=ps6.getNianfen();
	List<Prices6> st1=price6Service.getPrices6ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price6Service.insert(ps6);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps7",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs7(@RequestBody Prices7 ps7){
	Map<String, Object> ret=new HashMap<>();
	int year=ps7.getNianfen();
	List<Prices7> st1=price7Service.getPrices7ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price7Service.insert(ps7);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/insertps8",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object insertPs8(@RequestBody Prices8 ps8){
	Map<String, Object> ret=new HashMap<>();
	int year=ps8.getNianfen();
	List<Prices8> st1=price8Service.getPrices8ByNianfen(year);
	if (!st1.isEmpty()) {
		ret.put("message", "data exist!");
		return ret;
	}
	int tmpData=price8Service.insert(ps8);
	if (tmpData==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps1",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep1(@RequestBody Prices1 ps1){
	Map<String, Object> ret=new HashMap<>();
	if (ps1==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price1Service.updateByPrimaryKey(ps1)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}
@RequestMapping(value="/updateps2",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep2(@RequestBody Prices2 ps2){
	Map<String, Object> ret=new HashMap<>();
	if (ps2==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price2Service.updateByPrimaryKey(ps2)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps3",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep3(@RequestBody Prices3 ps3){
	Map<String, Object> ret=new HashMap<>();
	if (ps3==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price3Service.updateByPrimaryKey(ps3)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps4",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep4(@RequestBody Prices4 ps4){
	Map<String, Object> ret=new HashMap<>();
	if (ps4==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price4Service.updateByPrimaryKey(ps4)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps5",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep5(@RequestBody Prices5 ps5){
	Map<String, Object> ret=new HashMap<>();
	if (ps5==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price5Service.updateByPrimaryKey(ps5)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps6",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep6(@RequestBody Prices6 ps6){
	Map<String, Object> ret=new HashMap<>();
	if (ps6==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price6Service.updateByPrimaryKey(ps6)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps7",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep7(@RequestBody Prices7 ps7){
	Map<String, Object> ret=new HashMap<>();
	if (ps7==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price7Service.updateByPrimaryKey(ps7)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/updateps8",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object updatestep8(@RequestBody Prices8 ps8){
	Map<String, Object> ret=new HashMap<>();
	if (ps8==null) {
		ret.put("message", "failure");
		return ret;
	}
	if (price8Service.updateByPrimaryKey(ps8)==1) {
		ret.put("message", "success");
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}
@RequestMapping(value="/getps1",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep1s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices1> ps1=price1Service.getPrices1ByNianfen(Integer.parseInt(year));
	if (ps1!=null) {
		ret.put("message", "success");
		ret.put("data", ps1);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps2",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep2s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices2> ps2=price2Service.getPrices2ByNianfen(Integer.parseInt(year));
	if (ps2!=null) {
		ret.put("message", "success");
		ret.put("data", ps2);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps3",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep3s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices3> ps3=price3Service.getPrices3ByNianfen(Integer.parseInt(year));
	if (ps3!=null) {
		ret.put("message", "success");
		ret.put("data", ps3);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps4",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep4s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices4> ps4=price4Service.getPrices4ByNianfen(Integer.parseInt(year));
	if (ps4!=null) {
		ret.put("message", "success");
		ret.put("data", ps4);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps5",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep5s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices5> ps5=price5Service.getPrices5ByNianfen(Integer.parseInt(year));
	if (ps5!=null) {
		ret.put("message", "success");
		ret.put("data", ps5);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps6",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep6s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices6> ps6=price6Service.getPrices6ByNianfen(Integer.parseInt(year));
	if (ps6!=null) {
		ret.put("message", "success");
		ret.put("data", ps6);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps7",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep7s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices7> ps7=price7Service.getPrices7ByNianfen(Integer.parseInt(year));
	if (ps7!=null) {
		ret.put("message", "success");
		ret.put("data", ps7);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}

@RequestMapping(value="/getps8",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public Object getStep8s(@RequestBody Map<String, Object> args) {
	Map<String, Object> ret=new HashMap<>();
	String year=(String) args.get("year");
	List<Prices8> ps8=price8Service.getPrices8ByNianfen(Integer.parseInt(year));
	if (ps8!=null) {
		ret.put("message", "success");
		ret.put("data", ps8);
	}
	else {
		ret.put("message", "failure");
	}
	return ret;
}
}
